package cn.fastoo.common.dao.product;
import cn.fastoo.common.entity.product.ProductCategory;
import cn.fastoo.common.entity.product.ProductCategoryAttrgroup;
import cn.fastoo.common.sampleframe.dao.FastDao;
import cn.fastoo.common.sampleframe.dao.impl.FastDaoImpl;
import cn.fastoo.common.sampleframe.search.Search;
import cn.fastoo.common.sampleframe.springside.Collections3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;


@Component
@Transactional
public class ProductCategoryAttrgroupDao extends FastDaoImpl<ProductCategoryAttrgroup> implements FastDao<ProductCategoryAttrgroup> {


    @Autowired
    @Qualifier("mainDS")
    private void setJt(DataSource ds){
        this.jt = new JdbcTemplate(ds);
    }

    public Logger logger = LoggerFactory.getLogger(ProductCategoryAttrgroupDao.class);


    public List<ProductCategoryAttrgroup> findByProductCategoryId(Long productCategoryId) {
        return find(new Search().addSearchFilter("EQ_productCategoryId",productCategoryId));
    }


    public List<String> findProductAttrGroupIdsByProductCategoryId(Long productCategoryId){
        List<ProductCategoryAttrgroup> productCategoryAttrgroupList = findByProductCategoryId(productCategoryId);
        List<String> ids = new ArrayList<String>();
        if(Collections3.isNotEmpty(productCategoryAttrgroupList)){
            for (ProductCategoryAttrgroup p:productCategoryAttrgroupList) {
                ids.add(p.getProductAttrGroupId().toString());
            }
            return ids;
        }
         return ids;
    }
}
